import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:thinking/entity/_.dart';
import 'package:thinking/views/Search/searchDynamicValue.dart';
import 'package:thinking/views/Search/searchThinkValue.dart';
import 'package:thinking/views/Search/searchTopicValue.dart';
import 'package:thinking/views/Search/searchUserValue.dart';
import 'package:thinking/widget/_.dart';
import 'package:thinking/utils/_.dart';
import 'package:thinking/config/_.dart';

class IndexResultsList extends StatefulWidget {
  final String value;
  final int indexSearch;
  IndexResultsList({required this.value, required this.indexSearch});

  @override
  _IndexResultsList createState() => _IndexResultsList(
      value: Uri.decodeComponent(value), indexSearch: indexSearch);
}

class _IndexResultsList extends State<IndexResultsList>
    with SingleTickerProviderStateMixin {
  final String value;
  final int indexSearch;
  late TabController _tabController;
  List<String> tabList = ['think', '动态','话题','用户'];
  late List<PageEntity> pageEntityList ;
  List<Think> thinkData = [];
  List<DynamicDataEntity> dynamicData = [];

  _IndexResultsList({required this.value, required this.indexSearch});


  void initState() {
    super.initState();
    _tabController = TabController(
        length: tabList.length, vsync: this, initialIndex: indexSearch);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  PreferredSizeWidget bottom() {
    return PreferredSize(
      preferredSize: Size.fromHeight(35),
      child: TabBar(
        controller: _tabController,
        tabs: tabList
            .map((e) => Tab(
                  child: Padding(
                    padding: EdgeInsets.only(top: 6, bottom: 6),
                    child: Text(
                      e,
                    ),
                  ),
                ))
            .toList(),
        isScrollable: true,
        labelColor: ColorConfig.WhiteBackColor,
        labelStyle:TextStyle(fontSize: 16,fontWeight: FontWeight.w600),
        unselectedLabelColor: Color(0xB2FFFFF0),
        indicatorWeight: 2,
        indicatorColor: ColorConfig.WhiteBackColor,
        indicatorSize: TabBarIndicatorSize.tab,
      ),
    );
  }

  Widget search() {
    return GestureDetector(
      child: Panel(

                  child: ShowSearchWidget(
                    textVal: this.value,
                    backgroundColor: ColorConfig.WhiteBackColor,
                    textColor: ColorConfig.TextColor,
                    height: Screen.setHeight(40),
                  )
      ),
      onTap: (){
        Modular.to.pop();
      },
    );
  }



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 2,
        backgroundColor: ColorConfig.ThemeColor,
        automaticallyImplyLeading: false,
        titleSpacing: 0,
        title:  search(),
        bottom: bottom(),
      ),
      body: Container(
        margin: EdgeInsets.only(top: 2, bottom: 2),
        child: TabBarView(
          controller: _tabController,
          children: [SearchThinkValue(value: value,),SearchDynamicValue(value: value),SearchTopicValue(value: value),SearchUserValue(value: value)],
        ),
      ),
    );
  }
}

